import pymysql
import asyncio

db_2m = {
    'host': 'im-stage.c2u78hkbys5o.ap-east-1.rds.amazonaws.com',  # 主机
    'user': 'admin',  # 用户名
    'password': 'dtAIlpmcBbkcdmi7gppk',  # 密码
    'port': 3306,  # 端口 3306
    'database': 'im_sys'  # 数据库名
}


async def main():
    # 连接2m库
    connection_2m = pymysql.connect(**db_2m)
    # 创建游标对象
    cursor_2m = connection_2m.cursor()
    words = ""
    try:
        # 从2m库中选择所有数据
        cursor_2m.execute(f"SELECT word FROM sensitive_words;")
        rows = cursor_2m.fetchall()
        for row in rows:
            word = row[0]
            words += "," + word


    except (pymysql.Error) as error:
        print("导入数据表时发生错误:", error)

    # 关闭游标和连接
    cursor_2m.close()
    print(words)


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())